package io.renren.modules.dishes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.renren.modules.dishes.dao.ClassficationDao;
import io.renren.modules.dishes.entity.ClassificationEntity;
import io.renren.modules.dishes.service.ClassficationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("classficationService")
public class ClassficationServiceImpl extends ServiceImpl<ClassficationDao, ClassificationEntity> implements ClassficationService {

    @Autowired
    private ClassficationDao classficationDao;

    @Override
    public List<ClassificationEntity> getClassficationByUserId(String id) {
        QueryWrapper<ClassificationEntity> queryWrapper = new QueryWrapper<ClassificationEntity>()
                .eq("merchant_id",id);
        List<ClassificationEntity> classificationEntities = classficationDao.selectList(queryWrapper);
        return classificationEntities;
    }

    @Override
    public ClassificationEntity getClassficationById(String id) {

        QueryWrapper<ClassificationEntity> queryWrapper = new QueryWrapper<ClassificationEntity>()
                .eq("classify_id",id);
        return classficationDao.selectOne(queryWrapper);
    }

    @Override
    public Integer saveClassfication(ClassificationEntity classfication) {

        QueryWrapper<ClassificationEntity> wrapper=new QueryWrapper<ClassificationEntity>()
                .eq("merchant_id",classfication.getMerchantId())
                .eq("classify_name",classfication.getClassifyName());
        ClassificationEntity classificationEntity = classficationDao.selectOne(wrapper);
        if(classificationEntity!=null){
            return 0;
        }
        return classficationDao.insertClassfication(classfication);
    }

    @Override
    public Integer deleteBuId(String id) {
        return classficationDao.deleteById(id);
    }


}
